<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="non-essential-built-in-funcs.html" />
<link rel="prev" href="builtin.html" />
<link rel="parent" href="builtin.html" />
<link rel="next" href="non-essential-built-in-funcs.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>2.1 内置函数</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="2. built-in Objects"
  href="builtin.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="2. built-in Objects"
  href="builtin.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="2.2 non-essential Built-in Functions"
  href="non-essential-built-in-funcs.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python库参考</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">前一节:</b>
<a class="sectref" rel="prev" href="builtin.html">2. 内置对象</a>
<b class="navlabel">上一级:</b>
<a class="sectref" rel="parent" href="builtin.html">2. 内置对象</a>
<b class="navlabel">下一节:</b>
<a class="sectref" rel="next" href="non-essential-built-in-funcs.html">2.2 次要的内置函数</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION004100000000000000000"></a><a name="built-in-funcs"></a>
<br>
2.1 内置函数 
</h1>

<p>
  Python解释器拥有一些一直有效的内置函数。这里它们按照字母顺序被列出。

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-6' xml:id='l2h-6' class="function">__import__</tt></b>(</nobr></td>
  <td><var>name</var><big>[</big><var>, globals</var><big>[</big><var>, locals</var><big>[</big><var>, fromlist</var><big>[</big><var>, level</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  这个函数通过 <tt class="keyword">import</tt><a id='l2h-7' xml:id='l2h-7'></a>  声明被调用。  它主要存在以便于你可以使用其它有兼容接口的函数替换它，改变 <tt class="keyword">import</tt> 声明的语义。你为什么和怎样做这个替换的例子，参见标准库模块 <tt class="module">ihooks</tt><a id='l2h-82' xml:id='l2h-82'></a> 和
  <tt class="module"><a href="module-rexec.html">rexec</a></tt><a id='l2h-83' xml:id='l2h-83'></a>。也参见内置模块 <tt class="module"><a href="module-imp.html">imp</a></tt><a id='l2h-84' xml:id='l2h-84'></a>，它为构建你自己的<tt class="function">__import__()</tt>函数定义了一些有用的操作。
  <p>
例如，声明 "<tt class="samp">import spam</tt>" 结果是下列调用： <code>__import__('spam',</code> <code>globals(),</code>
  <code>locals(), [], -1)</code>；该声明 "<tt class="samp">from spam.ham import eggs</tt>"  结果是 "<tt class="samp">__import__('spam.ham', globals(), locals(),
  ['eggs'], -1)</tt>"。注意即使<code>locals()</code> 和<code>['eggs']</code> 作为参数被传递，<tt class="function">__import__()</tt> 函数不设置本地变量名称为 <code>eggs</code>；对于 import 声明这由后来生成的代码完成。(事实上，标准的实现从来不使用它的 <var>locals</var> 参数，并且仅使用它的 <var>globals</var> 判断<tt class="keyword"> import </tt>声明的包的上下文。)

  <p>
当 <var>name</var> 变量是 <code>package.module</code>格式时，一般地，返回顶层包 (第一个点前面的名称) ，<em>而不是</em>由 <var>name</var> 指定名称的模块。然而，当一个非空的 <var>fromlist</var> 参数被给定时，返回由
  <var>name</var> 指定名称的模块。这样做是为了兼容不同类型的 import 声明生成的字节码；当使用 "<tt class="samp">import spam.ham.eggs</tt>"时，顶层包 <tt class="module">spam</tt>
  必须放置在正在导入的命名空间中，但是当使用 "<tt class="samp">from
  spam.ham import eggs</tt>"时，<code>spam.ham</code> 子包必须被用来找到 <code>eggs</code> 变量。作为这种行为的一种替代，使用 <tt class="function">getattr()</tt> 提取需求的组件。例如，你可以定义下列助手：  <p>
<div class="verbatim"><pre>
def my_import(name):
    mod = __import__(name)
    components = name.split('.')
    for comp in components[1:]:
        mod = getattr(mod, comp)
    return mod
</pre></div>

<p>
<var>level</var> 指定是否使用绝对或相对导入。缺省是 <code>-1</code>，表示绝对和相对导入都将被尝试。<code>0</code> 意味着仅执行绝对导入。<var>level</var> 正的值表示相对于调用 <tt class="function">__import__ </tt>的模块的目录查找的父目录的数目。2.5版本中的改变：<span class="versionnote">增加 level 参数。</span><span class="versionnote">2.5版本中的改变：增加参数的关键字支持。</span>
</dl>
<dl>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-8' xml:id='l2h-8' class="function">abs</tt></b>(</nobr></td>
  <td><var>x</var>)</td></tr></table></dt>
<dd>
  返回一个数的绝对值。参数可以是一个简单的数或长整数或一个浮点数字。如果参数是一个复合数，返回它的大小。
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-9' xml:id='l2h-9' class="function">all</tt></b>(</nobr></td>
  <td><var>iterable</var>)</td></tr></table></dt>
<dd>
  如果 <var>iterable</var> 的所有元素为 true 返回True。相当于：
  <div class="verbatim"><pre>
     def all(iterable):
         for element in iterable:
             if not element:
                 return False
         return True
</pre></div>
  
<span class="versionnote">2.5版本中的新特性。</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-10' xml:id='l2h-10' class="function">any</tt></b>(</nobr></td>
  <td><var>iterable</var>)</td></tr></table></dt>
<dd>
  如果 <var>iterable</var> 的任一元素为 true 返回True。相当于：
  <div class="verbatim"><pre>
     def any(iterable):
         for element in iterable:
             if element:
                 return True
         return False
</pre></div>
  
<span class="versionnote">2.5版本中的新特性。</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-11' xml:id='l2h-11' class="function">basestring</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  这个抽象的类型是 <tt class="class">str</tt> 和 <tt class="class">unicode</tt>的超类。它不能被调用或实例化，但是它可以用来测试一个对象是否是 <tt class="class">str</tt> 或 <tt class="class">unicode </tt>的一个实例。<code>isinstance(obj, basestring)</code> 相当于
  <code>isinstance(obj, (str, unicode))</code>。<span class="versionnote">2.3版本中的新特性。</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-12' xml:id='l2h-12' class="function">bool</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>x</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  转换一个值为布尔型，用来标准的事实测试程序。如果 <var>x</var> 为false 或省略，返回<tt class="constant">False</tt>；否则返回 <tt class="constant">True</tt>。<tt class="class">bool</tt> 也是一个类，<tt class="class">int</tt>的一个子类。类 <tt class="class">bool</tt> 不能被进一步子类化。它的实例仅是 <tt class="constant">False</tt> 和 <tt class="constant">True</tt>。
  <p>
<a id='l2h-13' xml:id='l2h-13'></a>  
<span class="versionnote"> 2.2.1版本的新特性。</span><span class="versionnote">2.3版本中的改变：如果没有参数给定，这个函数返回 <tt class="constant">False</tt>。</span></dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-14' xml:id='l2h-14' class="function">callable</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  如果 <var>object</var> 参数出现回调返回 true，否者返回 false 。如果返回 true，它仍然可能是调用失败，但如果返回 false，调用 <var>object</var> 将绝不成功。注意被回调的类(调用一个类返回一个新的实例)；如果有一个 <tt class="method">__call__()</tt>
  方法类的实例被回调。
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-15' xml:id='l2h-15' class="function">chr</tt></b>(</nobr></td>
  <td><var>i</var>)</td></tr></table></dt>
<dd>
  返回 ASCII 码是整数
<var>i</var> 的一个字符串。例如，<code>chr(97)</code> 返回字符串<code>'a'</code>。这与 <tt class="function">ord()</tt>相反。参数必须在[0..255]的范围中，如果 <var>i</var> 在这个范围之外 <tt class="exception">ValueError</tt> 将被挂起。</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-16' xml:id='l2h-16' class="function">classmethod</tt></b>(</nobr></td>
  <td><var>function</var>)</td></tr></table></dt>
<dd>为 <var>function </var>返回一个类方法。
  <p>
一个类方法接受该类作为暗含的第一个参数，就像一个实例方法接受该实例。声明一个类方法，使用这个语法：
  <p>
<div class="verbatim"><pre>
class C:
    @classmethod
    def f(cls, arg1, arg2, ...): ...
</pre></div>

<p><code>@classmethod</code> 形式是一个函数修饰符 is a function decorator - see the description
  of function definitions in chapter 7 of the
  <em class="citetitle"><a
 href="../ref/ref.html"
 title="Python Reference Manual"
 >Python Reference Manual</a></em> for details.

<p>
It can be called either on the class (such as <code>C.f()</code>) or on an
  instance (such as <code>C().f()</code>).  The instance is ignored except for
  its class.
  If a class method is called for a derived class, the derived class
  object is passed as the implied first argument.

<p>
Class methods are different than C++ or Java static methods.
  If you want those, see <tt class="function">staticmethod()</tt> in this section.

<p>
For more information on class methods, consult the documentation on the
  standard type hierarchy in chapter 3 of the
  <em class="citetitle"><a
 href="../ref/types.html"
 title="Python Reference Manual"
 >Python Reference Manual</a></em> (at the bottom).
  
<span class="versionnote">New in version 2.2.</span>

<span class="versionnote">Changed in version 2.4:
Function decorator syntax added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-17' xml:id='l2h-17' class="function">cmp</tt></b>(</nobr></td>
  <td><var>x, y</var>)</td></tr></table></dt>
<dd>
  Compare the two objects <var>x</var> and <var>y</var> and return an integer
  according to the outcome.  The return value is negative if <code><var>x</var>
  &lt; <var>y</var></code>, zero if <code><var>x</var> == <var>y</var></code> and strictly positive if
  <code><var>x</var> &gt; <var>y</var></code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-18' xml:id='l2h-18' class="function">compile</tt></b>(</nobr></td>
  <td><var>string, filename, kind</var><big>[</big><var>,
                          flags</var><big>[</big><var>, dont_inherit</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Compile the <var>string</var> into a code object.  Code objects can be
  executed by an <tt class="keyword">exec</tt> statement or evaluated by a call to
  <tt class="function">eval()</tt>.  The <var>filename</var> argument should
  give the file from which the code was read; pass some recognizable value
  if it wasn't read from a file (<code>'&lt;string&gt;'</code> is commonly used).
  The <var>kind</var> argument specifies what kind of code must be
  compiled; it can be <code>'exec'</code> if <var>string</var> consists of a
  sequence of statements, <code>'eval'</code> if it consists of a single
  expression, or <code>'single'</code> if it consists of a single
  interactive statement (in the latter case, expression statements
  that evaluate to something else than <code>None</code> will be printed).

<p>
When compiling multi-line statements, two caveats apply: line
  endings must be represented by a single newline character
  (<code>'\n'</code>), and the input must be terminated by at least one
  newline character.  If line endings are represented by
  <code>'\r\n'</code>, use the string <tt class="method">replace()</tt> method to
  change them into <code>'\n'</code>.

<p>
The optional arguments <var>flags</var> and <var>dont_inherit</var>
  (which are new in Python 2.2) control which future statements (see
  <a class="rfc" id='rfcref-97633' xml:id='rfcref-97633'
href="http://www.python.org/peps/pep-0236.html">PEP 236</a>) affect the compilation of <var>string</var>.  If neither is
  present (or both are zero) the code is compiled with those future
  statements that are in effect in the code that is calling compile.
  If the <var>flags</var> argument is given and <var>dont_inherit</var> is not
  (or is zero) then the future statements specified by the <var>flags</var>
  argument are used in addition to those that would be used anyway.
  If <var>dont_inherit</var> is a non-zero integer then the <var>flags</var>
  argument is it - the future statements in effect around the call to
  compile are ignored.

<p>
Future statements are specified by bits which can be bitwise or-ed
  together to specify multiple statements.  The bitfield required to
  specify a given feature can be found as the <tt class="member">compiler_flag</tt>
  attribute on the <tt class="class">_Feature</tt> instance in the
  <tt class="module">__future__</tt> module.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-19' xml:id='l2h-19' class="function">complex</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>real</var><big>[</big><var>, imag</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Create a complex number with the value <var>real</var> + <var>imag</var>*j or
  convert a string or number to a complex number.  If the first
  parameter is a string, it will be interpreted as a complex number
  and the function must be called without a second parameter.  The
  second parameter can never be a string.
  Each argument may be any numeric type (including complex).
  If <var>imag</var> is omitted, it defaults to zero and the function
  serves as a numeric conversion function like <tt class="function">int()</tt>,
  <tt class="function">long()</tt> and <tt class="function">float()</tt>.  If both arguments
  are omitted, returns <code>0j</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-20' xml:id='l2h-20' class="function">delattr</tt></b>(</nobr></td>
  <td><var>object, name</var>)</td></tr></table></dt>
<dd>
  This is a relative of <tt class="function">setattr()</tt>.  The arguments are an
  object and a string.  The string must be the name
  of one of the object's attributes.  The function deletes
  the named attribute, provided the object allows it.  For example,
  <code>delattr(<var>x</var>, '<var>foobar</var>')</code> is equivalent to
  <code>del <var>x</var>.<var>foobar</var></code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-21' xml:id='l2h-21' class="function">dict</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>arg</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a new dictionary initialized from an optional positional
  argument or from a set of keyword arguments.
  If no arguments are given, return a new empty dictionary.
  If the positional argument <var>arg</var> is a mapping object, return a dictionary
  mapping the same keys to the same values as does the mapping object.
  Otherwise the positional argument must be a sequence, a container that
  supports iteration, or an iterator object.  The elements of the argument
  must each also be of one of those kinds, and each must in turn contain
  exactly two objects.  The first is used as a key in the new dictionary,
  and the second as the key's value.  If a given key is seen more than
  once, the last value associated with it is retained in the new
  dictionary.

<p>
If keyword arguments are given, the keywords themselves with their
  associated values are added as items to the dictionary. If a key
  is specified both in the positional argument and as a keyword argument,
  the value associated with the keyword is retained in the dictionary.
  For example, these all return a dictionary equal to
  <code>{"one": 2, "two": 3}</code>:

<p>

<ul>
<li><code>dict({'one': 2, 'two': 3})</code>
</li>
<li><code>dict({'one': 2, 'two': 3}.items())</code>
</li>
<li><code>dict({'one': 2, 'two': 3}.iteritems())</code>
</li>
<li><code>dict(zip(('one', 'two'), (2, 3)))</code>
</li>
<li><code>dict([['two', 3], ['one', 2]])</code>
</li>
<li><code>dict(one=2, two=3)</code>
</li>
<li><code>dict([(['one', 'two'][i-2], i) for i in (2, 3)])</code>
  
</li>
</ul>

<p>

<span class="versionnote">New in version 2.2.</span>

<span class="versionnote">Changed in version 2.3:
Support for building a dictionary from keyword
                  arguments added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-22' xml:id='l2h-22' class="function">dir</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>object</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Without arguments, return the list of names in the current local
  symbol table.  With an argument, attempts to return a list of valid
  attributes for that object.  This information is gleaned from the
  object's <tt class="member">__dict__</tt> attribute, if defined, and from the class
  or type object.  The list is not necessarily complete.
  If the object is a module object, the list contains the names of the
  module's attributes.
  If the object is a type or class object,
  the list contains the names of its attributes,
  and recursively of the attributes of its bases.
  Otherwise, the list contains the object's attributes' names,
  the names of its class's attributes,
  and recursively of the attributes of its class's base classes.
  The resulting list is sorted alphabetically.
  For example:

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; import struct
&gt;&gt;&gt; dir()
['__builtins__', '__doc__', '__name__', 'struct']
&gt;&gt;&gt; dir(struct)
['__doc__', '__name__', 'calcsize', 'error', 'pack', 'unpack']
</pre></div>

<p>
<span class="note"><b class="label">Note:</b>
Because <tt class="function">dir()</tt> is supplied primarily as a convenience
  for use at an interactive prompt,
  it tries to supply an interesting set of names more than it tries to
  supply a rigorously or consistently defined set of names,
  and its detailed behavior may change across releases.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-23' xml:id='l2h-23' class="function">divmod</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
  Take two (non complex) numbers as arguments and return a pair of numbers
  consisting of their quotient and remainder when using long division.  With
  mixed operand types, the rules for binary arithmetic operators apply.  For
  plain and long integers, the result is the same as
  <code>(<var>a</var> // <var>b</var>, <var>a</var> % <var>b</var>)</code>.
  For floating point numbers the result is <code>(<var>q</var>, <var>a</var> %
  <var>b</var>)</code>, where <var>q</var> is usually <code>math.floor(<var>a</var> /
  <var>b</var>)</code> but may be 1 less than that.  In any case <code><var>q</var> *
  <var>b</var> + <var>a</var> % <var>b</var></code> is very close to <var>a</var>, if
  <code><var>a</var> % <var>b</var></code> is non-zero it has the same sign as
  <var>b</var>, and <code>0 &lt;= abs(<var>a</var> % <var>b</var>) &lt; abs(<var>b</var>)</code>.

<p>

<span class="versionnote">Changed in version 2.3:
Using <tt class="function">divmod()</tt> with complex numbers is
                  deprecated.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-24' xml:id='l2h-24' class="function">enumerate</tt></b>(</nobr></td>
  <td><var>iterable</var>)</td></tr></table></dt>
<dd>
  Return an enumerate object. <var>iterable</var> must be a sequence, an
  iterator, or some other object which supports iteration.  The
  <tt class="method">next()</tt> method of the iterator returned by
  <tt class="function">enumerate()</tt> returns a tuple containing a count (from
  zero) and the corresponding value obtained from iterating over
  <var>iterable</var>.  <tt class="function">enumerate()</tt> is useful for obtaining an
  indexed series: <code>(0, seq[0])</code>, <code>(1, seq[1])</code>, <code>(2,
  seq[2])</code>, ....
  
<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-25' xml:id='l2h-25' class="function">eval</tt></b>(</nobr></td>
  <td><var>expression</var><big>[</big><var>, globals</var><big>[</big><var>, locals</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  The arguments are a string and optional globals and locals.  If provided,
  <var>globals</var> must be a dictionary.  If provided, <var>locals</var> can be
  any mapping object.  
<span class="versionnote">Changed in version 2.4:
formerly <var>locals</var> was required
  to be a dictionary.</span>

<p>
The <var>expression</var> argument is parsed and evaluated as a Python
  expression (technically speaking, a condition list) using the
  <var>globals</var> and <var>locals</var> dictionaries as global and local name
  space.  If the <var>globals</var> dictionary is present and lacks
  '__builtins__', the current globals are copied into <var>globals</var> before
  <var>expression</var> is parsed.  This means that <var>expression</var>
  normally has full access to the standard
  <tt class="module"><a href="module-builtin.html">__builtin__</a></tt> module and restricted environments
  are propagated.  If the <var>locals</var> dictionary is omitted it defaults to
  the <var>globals</var> dictionary.  If both dictionaries are omitted, the
  expression is executed in the environment where <tt class="keyword">eval</tt> is
  called.  The return value is the result of the evaluated expression.
  Syntax errors are reported as exceptions.  Example:

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; x = 1
&gt;&gt;&gt; print eval('x+1')
2
</pre></div>

<p>
This function can also be used to execute arbitrary code objects
  (such as those created by <tt class="function">compile()</tt>).  In this case pass
  a code object instead of a string.  The code object must have been
  compiled passing <code>'eval'</code> as the <var>kind</var> argument.

<p>
Hints: dynamic execution of statements is supported by the
  <tt class="keyword">exec</tt> statement.  Execution of statements from a file is
  supported by the <tt class="function">execfile()</tt> function.  The
  <tt class="function">globals()</tt> and <tt class="function">locals()</tt> functions returns the
  current global and local dictionary, respectively, which may be
  useful to pass around for use by <tt class="function">eval()</tt> or
  <tt class="function">execfile()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-26' xml:id='l2h-26' class="function">execfile</tt></b>(</nobr></td>
  <td><var>filename</var><big>[</big><var>, globals</var><big>[</big><var>, locals</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  This function is similar to the
  <tt class="keyword">exec</tt> statement, but parses a file instead of a string.  It
  is different from the <tt class="keyword">import</tt> statement in that it does not
  use the module administration -- it reads the file unconditionally
  and does not create a new module.<a name="tex2html2"
  href="#foot419"><sup>2.2</sup></a>
<p>
The arguments are a file name and two optional dictionaries.  The file is
  parsed and evaluated as a sequence of Python statements (similarly to a
  module) using the <var>globals</var> and <var>locals</var> dictionaries as global and
  local namespace. If provided, <var>locals</var> can be any mapping object.
  
<span class="versionnote">Changed in version 2.4:
formerly <var>locals</var> was required to be a dictionary.</span>

  If the <var>locals</var> dictionary is omitted it defaults to the <var>globals</var>
  dictionary. If both dictionaries are omitted, the expression is executed in
  the environment where <tt class="function">execfile()</tt> is called.  The return value is
  <code>None</code>.

<p>
<span class="warning"><b class="label">Warning:</b>
The default <var>locals</var> act as described for function
  <tt class="function">locals()</tt> below:  modifications to the default <var>locals</var>
  dictionary should not be attempted.  Pass an explicit <var>locals</var>
  dictionary if you need to see effects of the code on <var>locals</var> after
  function <tt class="function">execfile()</tt> returns.  <tt class="function">execfile()</tt> cannot
  be used reliably to modify a function's locals.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-27' xml:id='l2h-27' class="function">file</tt></b>(</nobr></td>
  <td><var>filename</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Constructor function for the <tt class="class">file</tt> type, described further 
  in section&nbsp;<a href="bltin-file-objects.html#bltin-file-objects">3.9</a>, ``<a class="ulink" href="bltin-file-objects.html"
  >File
  Objects</a>''.  The constructor's arguments
  are the same as those of the <tt class="function">open()</tt> built-in function
  described below.

<p>
When opening a file, it's preferable to use <tt class="function">open()</tt> instead of 
  invoking this constructor directly.  <tt class="class">file</tt> is more suited to
  type testing (for example, writing "<tt class="samp">isinstance(f, file)</tt>").

<p>

<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-28' xml:id='l2h-28' class="function">filter</tt></b>(</nobr></td>
  <td><var>function, iterable</var>)</td></tr></table></dt>
<dd>
  Construct a list from those elements of <var>iterable</var> for which
  <var>function</var> returns true.  <var>iterable</var> may be either a sequence, a
  container which supports iteration, or an iterator,  If <var>iterable</var>
  is a string or a tuple, the result
  also has that type; otherwise it is always a list.  If <var>function</var> is
  <code>None</code>, the identity function is assumed, that is, all elements of
  <var>iterable</var> that are false are removed.

<p>
Note that <code>filter(function, <var>iterable</var>)</code> is equivalent to
  <code>[item for item in <var>iterable</var> if function(item)]</code> if function is
  not <code>None</code> and <code>[item for item in <var>iterable</var> if item]</code> if
  function is <code>None</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-29' xml:id='l2h-29' class="function">float</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>x</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Convert a string or a number to floating point.  If the argument is a
  string, it must contain a possibly signed decimal or floating point
  number, possibly embedded in whitespace. Otherwise, the argument may be a plain
  or long integer or a floating point number, and a floating point
  number with the same value (within Python's floating point
  precision) is returned.  If no argument is given, returns <code>0.0</code>.

<p>
<span class="note"><b class="label">Note:</b>
When passing in a string, values for NaN<a id='l2h-30' xml:id='l2h-30'></a>
  and Infinity<a id='l2h-31' xml:id='l2h-31'></a> may be returned, depending on the
  underlying C library.  The specific set of strings accepted which
  cause these values to be returned depends entirely on the C library
  and is known to vary.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-32' xml:id='l2h-32' class="function">frozenset</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>iterable</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a frozenset object whose elements are taken from <var>iterable</var>.
  Frozensets are sets that have no update methods but can be hashed and
  used as members of other sets or as dictionary keys.  The elements of
  a frozenset must be immutable themselves.  To represent sets of sets,
  the inner sets should also be <tt class="class">frozenset</tt> objects.  If
  <var>iterable</var> is not specified, returns a new empty set,
  <code>frozenset([])</code>.
  
<span class="versionnote">New in version 2.4.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-33' xml:id='l2h-33' class="function">getattr</tt></b>(</nobr></td>
  <td><var>object, name</var><big>[</big><var>, default</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the value of the named attributed of <var>object</var>.  <var>name</var>
  must be a string.  If the string is the name of one of the object's
  attributes, the result is the value of that attribute.  For example,
  <code>getattr(x, 'foobar')</code> is equivalent to <code>x.foobar</code>.  If the
  named attribute does not exist, <var>default</var> is returned if provided,
  otherwise <tt class="exception">AttributeError</tt> is raised.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-34' xml:id='l2h-34' class="function">globals</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a dictionary representing the current global symbol table.
  This is always the dictionary of the current module (inside a
  function or method, this is the module where it is defined, not the
  module from which it is called).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-35' xml:id='l2h-35' class="function">hasattr</tt></b>(</nobr></td>
  <td><var>object, name</var>)</td></tr></table></dt>
<dd>
  The arguments are an object and a string.  The result is <code>True</code> if the
  string is the name of one of the object's attributes, <code>False</code> if not.
  (This is implemented by calling <code>getattr(<var>object</var>,
  <var>name</var>)</code> and seeing whether it raises an exception or not.)
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-36' xml:id='l2h-36' class="function">hash</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return the hash value of the object (if it has one).  Hash values
  are integers.  They are used to quickly compare dictionary
  keys during a dictionary lookup.  Numeric values that compare equal
  have the same hash value (even if they are of different types, as is
  the case for 1 and 1.0).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-37' xml:id='l2h-37' class="function">help</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>object</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Invoke the built-in help system.  (This function is intended for
  interactive use.)  If no argument is given, the interactive help
  system starts on the interpreter console.  If the argument is a
  string, then the string is looked up as the name of a module,
  function, class, method, keyword, or documentation topic, and a
  help page is printed on the console.  If the argument is any other
  kind of object, a help page on the object is generated.
  
<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-38' xml:id='l2h-38' class="function">hex</tt></b>(</nobr></td>
  <td><var>x</var>)</td></tr></table></dt>
<dd>
  Convert an integer number (of any size) to a hexadecimal string.
  The result is a valid Python expression.
  
<span class="versionnote">Changed in version 2.4:
Formerly only returned an unsigned literal.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-39' xml:id='l2h-39' class="function">id</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return the ``identity'' of an object.  This is an integer (or long
  integer) which is guaranteed to be unique and constant for this
  object during its lifetime.  Two objects with non-overlapping lifetimes
  may have the same <tt class="function">id()</tt> value.  (Implementation
  note: this is the address of the object.)
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-40' xml:id='l2h-40' class="function">input</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>prompt</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Equivalent to <code>eval(raw_input(<var>prompt</var>))</code>.
  <span class="warning"><b class="label">Warning:</b>
This function is not safe from user errors!  It
  expects a valid Python expression as input; if the input is not
  syntactically valid, a <tt class="exception">SyntaxError</tt> will be raised.
  Other exceptions may be raised if there is an error during
  evaluation.  (On the other hand, sometimes this is exactly what you
  need when writing a quick script for expert use.)</span>

<p>
If the <tt class="module"><a href="module-readline.html">readline</a></tt> module was loaded, then
  <tt class="function">input()</tt> will use it to provide elaborate line editing and
  history features.

<p>
Consider using the <tt class="function">raw_input()</tt> function for general input
  from users.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-41' xml:id='l2h-41' class="function">int</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>x</var><big>[</big><var>, radix</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Convert a string or number to a plain integer.  If the argument is a
  string, it must contain a possibly signed decimal number
  representable as a Python integer, possibly embedded in whitespace.
  The <var>radix</var> parameter gives the base for the
  conversion and may be any integer in the range [2, 36], or zero.  If
  <var>radix</var> is zero, the proper radix is guessed based on the
  contents of string; the interpretation is the same as for integer
  literals.  If <var>radix</var> is specified and <var>x</var> is not a string,
  <tt class="exception">TypeError</tt> is raised.
  Otherwise, the argument may be a plain or
  long integer or a floating point number.  Conversion of floating
  point numbers to integers truncates (towards zero).
  If the argument is outside the integer range a long object will
  be returned instead.  If no arguments are given, returns <code>0</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-42' xml:id='l2h-42' class="function">isinstance</tt></b>(</nobr></td>
  <td><var>object, classinfo</var>)</td></tr></table></dt>
<dd>
  Return true if the <var>object</var> argument is an instance of the
  <var>classinfo</var> argument, or of a (direct or indirect) subclass
  thereof.  Also return true if <var>classinfo</var> is a type object
  (new-style class) and <var>object</var> is an object of that type or of a
  (direct or indirect) subclass thereof.  If <var>object</var> is not a
  class instance or an object of the given type, the function always
  returns false.  If <var>classinfo</var> is neither a class object nor a
  type object, it may be a tuple of class or type objects, or may
  recursively contain other such tuples (other sequence types are not
  accepted).  If <var>classinfo</var> is not a class, type, or tuple of
  classes, types, and such tuples, a <tt class="exception">TypeError</tt> exception
  is raised.
  
<span class="versionnote">Changed in version 2.2:
Support for a tuple of type information was added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-43' xml:id='l2h-43' class="function">issubclass</tt></b>(</nobr></td>
  <td><var>class, classinfo</var>)</td></tr></table></dt>
<dd>
  Return true if <var>class</var> is a subclass (direct or indirect) of
  <var>classinfo</var>.  A class is considered a subclass of itself.
  <var>classinfo</var> may be a tuple of class objects, in which case every
  entry in <var>classinfo</var> will be checked. In any other case, a
  <tt class="exception">TypeError</tt> exception is raised.
  
<span class="versionnote">Changed in version 2.3:
Support for a tuple of type information was added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-44' xml:id='l2h-44' class="function">iter</tt></b>(</nobr></td>
  <td><var>o</var><big>[</big><var>, sentinel</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return an iterator object.  The first argument is interpreted very
  differently depending on the presence of the second argument.
  Without a second argument, <var>o</var> must be a collection object which
  supports the iteration protocol (the <tt class="method">__iter__()</tt> method), or
  it must support the sequence protocol (the <tt class="method">__getitem__()</tt>
  method with integer arguments starting at <code>0</code>).  If it does not
  support either of those protocols, <tt class="exception">TypeError</tt> is raised.
  If the second argument, <var>sentinel</var>, is given, then <var>o</var> must
  be a callable object.  The iterator created in this case will call
  <var>o</var> with no arguments for each call to its <tt class="method">next()</tt>
  method; if the value returned is equal to <var>sentinel</var>,
  <tt class="exception">StopIteration</tt> will be raised, otherwise the value will
  be returned.
  
<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-45' xml:id='l2h-45' class="function">len</tt></b>(</nobr></td>
  <td><var>s</var>)</td></tr></table></dt>
<dd>
  Return the length (the number of items) of an object.  The argument
  may be a sequence (string, tuple or list) or a mapping (dictionary).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-46' xml:id='l2h-46' class="function">list</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>iterable</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a list whose items are the same and in the same order as
  <var>iterable</var>'s items.  <var>iterable</var> may be either a sequence, a
  container that supports iteration, or an iterator object.  If
  <var>iterable</var> is already a list, a copy is made and returned,
  similar to <code><var>iterable</var>[:]</code>.  For instance,
  <code>list('abc')</code> returns <code>['a', 'b', 'c']</code> and <code>list(
  (1, 2, 3) )</code> returns <code>[1, 2, 3]</code>.  If no argument is given,
  returns a new empty list, <code>[]</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-47' xml:id='l2h-47' class="function">locals</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Update and return a dictionary representing the current local symbol table.
  <span class="warning"><b class="label">Warning:</b>
The contents of this dictionary should not be modified;
  changes may not affect the values of local variables used by the
  interpreter.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-48' xml:id='l2h-48' class="function">long</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>x</var><big>[</big><var>, radix</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Convert a string or number to a long integer.  If the argument is a
  string, it must contain a possibly signed number of
  arbitrary size, possibly embedded in whitespace. The
  <var>radix</var> argument is interpreted in the same way as for
  <tt class="function">int()</tt>, and may only be given when <var>x</var> is a string.
  Otherwise, the argument may be a plain or
  long integer or a floating point number, and a long integer with
  the same value is returned.    Conversion of floating
  point numbers to integers truncates (towards zero).  If no arguments
  are given, returns <code>0L</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-49' xml:id='l2h-49' class="function">map</tt></b>(</nobr></td>
  <td><var>function, iterable, ...</var>)</td></tr></table></dt>
<dd>
  Apply <var>function</var> to every item of <var>iterable</var> and return a list
  of the results.  If additional <var>iterable</var> arguments are passed,
  <var>function</var> must take that many arguments and is applied to the
  items from all iterables in parallel.  If one iterable is shorter than another it
  is assumed to be extended with <code>None</code> items.  If <var>function</var>
  is <code>None</code>, the identity function is assumed; if there are
  multiple arguments, <tt class="function">map()</tt> returns a list consisting
  of tuples containing the corresponding items from all iterables (a kind
  of transpose operation).  The <var>iterable</var> arguments may be a sequence 
  or any iterable object; the result is always a list.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-50' xml:id='l2h-50' class="function">max</tt></b>(</nobr></td>
  <td><var>iterable</var><big>[</big><var>, args...</var><big>]</big><var></var><big>[</big><var>key</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  With a single argument <var>iterable</var>, return the largest item of a
  non-empty iterable (such as a string, tuple or list).  With more
  than one argument, return the largest of the arguments.

<p>
The optional <var>key</var> argument specifies a one-argument ordering
  function like that used for <tt class="method">list.sort()</tt>.  The <var>key</var>
  argument, if supplied, must be in keyword form (for example,
  "<tt class="samp">max(a,b,c,key=func)</tt>").
  
<span class="versionnote">Changed in version 2.5:
Added support for the optional <var>key</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-51' xml:id='l2h-51' class="function">min</tt></b>(</nobr></td>
  <td><var>iterable</var><big>[</big><var>, args...</var><big>]</big><var></var><big>[</big><var>key</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  With a single argument <var>iterable</var>, return the smallest item of a
  non-empty iterable (such as a string, tuple or list).  With more
  than one argument, return the smallest of the arguments.

<p>
The optional <var>key</var> argument specifies a one-argument ordering
  function like that used for <tt class="method">list.sort()</tt>.  The <var>key</var>
  argument, if supplied, must be in keyword form (for example,
  "<tt class="samp">min(a,b,c,key=func)</tt>").
  
<span class="versionnote">Changed in version 2.5:
Added support for the optional <var>key</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-52' xml:id='l2h-52' class="function">object</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a new featureless object.  <tt class="class">object</tt> is a base
  for all new style classes.  It has the methods that are common
  to all instances of new style classes.
  
<span class="versionnote">New in version 2.2.</span>

<p>

<span class="versionnote">Changed in version 2.3:
This function does not accept any arguments.
  Formerly, it accepted arguments but ignored them.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-53' xml:id='l2h-53' class="function">oct</tt></b>(</nobr></td>
  <td><var>x</var>)</td></tr></table></dt>
<dd>
  Convert an integer number (of any size) to an octal string.  The
  result is a valid Python expression.
  
<span class="versionnote">Changed in version 2.4:
Formerly only returned an unsigned literal.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-54' xml:id='l2h-54' class="function">open</tt></b>(</nobr></td>
  <td><var>filename</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Open a file, returning an object of the <tt class="class">file</tt> type described
  in section&nbsp;<a href="bltin-file-objects.html#bltin-file-objects">3.9</a>, ``<a class="ulink" href="bltin-file-objects.html"
  >File
  Objects</a>''.  If the file cannot be opened,
  <tt class="exception">IOError</tt> is raised.  When opening a file, it's
  preferable to use <tt class="function">open()</tt> instead of invoking the
  <tt class="class">file</tt> constructor directly.

<p>
The first two arguments are the same as for <code>stdio</code>'s
  <tt class="cfunction">fopen()</tt>: <var>filename</var> is the file name to be opened,
  and <var>mode</var> is a string indicating how the file is to be opened.

<p>
The most commonly-used values of <var>mode</var> are <code>'r'</code> for
  reading, <code>'w'</code> for writing (truncating the file if it already
  exists), and <code>'a'</code> for appending (which on <em>some</em> <span class="Unix">Unix</span>
  systems means that <em>all</em> writes append to the end of the file
  regardless of the current seek position).  If <var>mode</var> is omitted,
  it defaults to <code>'r'</code>.  When opening a binary file, you should
  append <code>'b'</code> to the <var>mode</var> value to open the file in binary
  mode, which will improve portability.  (Appending <code>'b'</code> is
  useful even on systems that don't treat binary and text files
  differently, where it serves as documentation.)  See below for more
  possible values of <var>mode</var>.

<p>
<a id='l2h-85' xml:id='l2h-85'></a>
  The optional <var>bufsize</var> argument specifies the
  file's desired buffer size: 0 means unbuffered, 1 means line
  buffered, any other positive value means use a buffer of
  (approximately) that size.  A negative <var>bufsize</var> means to use
  the system default, which is usually line buffered for tty
  devices and fully buffered for other files.  If omitted, the system
  default is used.<a name="tex2html3"
  href="#foot1197"><sup>2.3</sup></a>
<p>
Modes <code>'r+'</code>, <code>'w+'</code> and <code>'a+'</code> open the file for
  updating (note that <code>'w+'</code> truncates the file).  Append
  <code>'b'</code> to the mode to open the file in binary mode, on systems
  that differentiate between binary and text files; on systems
  that don't have this distinction, adding the <code>'b'</code> has no effect.

<p>
In addition to the standard <tt class="cfunction">fopen()</tt> values <var>mode</var>
  may be <code>'U'</code> or <code>'rU'</code>.  Python is usually built with universal
  newline support; supplying <code>'U'</code> opens the file as a text file, but
  lines may be terminated by any of the following: the <span class="Unix">Unix</span> end-of-line
  convention <code>'\n'</code>, 
  the Macintosh convention <code>'\r'</code>, or the Windows
  convention <code>'\r\n'</code>. All of these external representations are seen as
  <code>'\n'</code>
  by the Python program. If Python is built without universal newline support
  a <var>mode</var> with <code>'U'</code> is the same as normal text mode.  Note that
  file objects so opened also have an attribute called
  <tt class="member">newlines</tt> which has a value of <code>None</code> (if no newlines
  have yet been seen), <code>'\n'</code>, <code>'\r'</code>, <code>'\r\n'</code>,
  or a tuple containing all the newline types seen.

<p>
Python enforces that the mode, after stripping <code>'U'</code>, begins with
  <code>'r'</code>, <code>'w'</code> or <code>'a'</code>.

<p>

<span class="versionnote">Changed in version 2.5:
Restriction on first letter of mode string
                  introduced.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-55' xml:id='l2h-55' class="function">ord</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
  Given a string of length one, return an integer representing the
  Unicode code point of the character when the argument is a unicode object,
  or the value of the byte when the argument is an 8-bit string.
  For example, <code>ord('a')</code> returns the integer <code>97</code>,
  <code>ord(u'\u2020')</code> returns <code>8224</code>.  This is the inverse of
  <tt class="function">chr()</tt> for 8-bit strings and of <tt class="function">unichr()</tt> for unicode
  objects.  If a unicode argument is given and Python was built with
  UCS2 Unicode, then the character's code point must be in the range
  [0..65535] inclusive; otherwise the string length is two, and a
  <tt class="exception">TypeError</tt> will be raised.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-56' xml:id='l2h-56' class="function">pow</tt></b>(</nobr></td>
  <td><var>x, y</var><big>[</big><var>, z</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return <var>x</var> to the power <var>y</var>; if <var>z</var> is present, return
  <var>x</var> to the power <var>y</var>, modulo <var>z</var> (computed more
  efficiently than <code>pow(<var>x</var>, <var>y</var>) % <var>z</var></code>).
  The two-argument form <code>pow(<var>x</var>, <var>y</var>)</code> is equivalent to using
  the power operator: <code><var>x</var>**<var>y</var></code>.

<p>
The arguments must have numeric types.  With mixed operand types, the
  coercion rules for binary arithmetic operators apply.  For int and
  long int operands, the result has the same type as the operands
  (after coercion) unless the second argument is negative; in that
  case, all arguments are converted to float and a float result is
  delivered.  For example, <code>10**2</code> returns <code>100</code>, but
  <code>10**-2</code> returns <code>0.01</code>.  (This last feature was added in
  Python 2.2.  In Python 2.1 and before, if both arguments were of integer
  types and the second argument was negative, an exception was raised.)
  If the second argument is negative, the third argument must be omitted.
  If <var>z</var> is present, <var>x</var> and <var>y</var> must be of integer types,
  and <var>y</var> must be non-negative.  (This restriction was added in
  Python 2.2.  In Python 2.1 and before, floating 3-argument <code>pow()</code>
  returned platform-dependent results depending on floating-point
  rounding accidents.)
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-57' xml:id='l2h-57' class="function">property</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>fget</var><big>[</big><var>, fset</var><big>[</big><var>,
                           fdel</var><big>[</big><var>, doc</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a property attribute for new-style classes (classes that
  derive from <tt class="class">object</tt>).

<p>
<var>fget</var> is a function for getting an attribute value, likewise
  <var>fset</var> is a function for setting, and <var>fdel</var> a function
  for del'ing, an attribute.  Typical use is to define a managed attribute x:

<p>
<div class="verbatim"><pre>
class C(object):
    def __init__(self): self._x = None
    def getx(self): return self._x
    def setx(self, value): self._x = value
    def delx(self): del self._x
    x = property(getx, setx, delx, "I'm the 'x' property.")
</pre></div>

<p>
If given, <var>doc</var> will be the docstring of the property attribute.
  Otherwise, the property will copy <var>fget</var>'s docstring (if it
  exists).  This makes it possible to create read-only properties
  easily using <tt class="function">property()</tt> as a decorator:

<p>
<div class="verbatim"><pre>
class Parrot(object):
    def __init__(self):
        self._voltage = 100000

    @property
    def voltage(self):
        """Get the current voltage."""
        return self._voltage
</pre></div>

<p>
turns the <tt class="method">voltage()</tt> method into a ``getter'' for a read-only
  attribute with the same name.

<p>

<span class="versionnote">New in version 2.2.</span>

<span class="versionnote">Changed in version 2.5:
Use <var>fget</var>'s docstring if no <var>doc</var> given.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-58' xml:id='l2h-58' class="function">range</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>start,</var><big>]</big><var> stop</var><big>[</big><var>, step</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  This is a versatile function to create lists containing arithmetic
  progressions.  It is most often used in <tt class="keyword">for</tt> loops.  The
  arguments must be plain integers.  If the <var>step</var> argument is
  omitted, it defaults to <code>1</code>.  If the <var>start</var> argument is
  omitted, it defaults to <code>0</code>.  The full form returns a list of
  plain integers <code>[<var>start</var>, <var>start</var> + <var>step</var>,
  <var>start</var> + 2 * <var>step</var>, ...]</code>.  If <var>step</var> is positive,
  the last element is the largest <code><var>start</var> + <var>i</var> *
  <var>step</var></code> less than <var>stop</var>; if <var>step</var> is negative, the last
  element is the smallest <code><var>start</var> + <var>i</var> * <var>step</var></code>
  greater than <var>stop</var>.  <var>step</var> must not be zero (or else
  <tt class="exception">ValueError</tt> is raised).  Example:

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
&gt;&gt;&gt; range(1, 11)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
&gt;&gt;&gt; range(0, 30, 5)
[0, 5, 10, 15, 20, 25]
&gt;&gt;&gt; range(0, 10, 3)
[0, 3, 6, 9]
&gt;&gt;&gt; range(0, -10, -1)
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
&gt;&gt;&gt; range(0)
[]
&gt;&gt;&gt; range(1, 0)
[]
</pre></div>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-59' xml:id='l2h-59' class="function">raw_input</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>prompt</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  If the <var>prompt</var> argument is present, it is written to standard output
  without a trailing newline.  The function then reads a line from input,
  converts it to a string (stripping a trailing newline), and returns that.
  When EOF is read, <tt class="exception">EOFError</tt> is raised. Example:

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; s = raw_input('--&gt; ')
--&gt; Monty Python's Flying Circus
&gt;&gt;&gt; s
"Monty Python's Flying Circus"
</pre></div>

<p>
If the <tt class="module"><a href="module-readline.html">readline</a></tt> module was loaded, then
  <tt class="function">raw_input()</tt> will use it to provide elaborate
  line editing and history features.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-60' xml:id='l2h-60' class="function">reduce</tt></b>(</nobr></td>
  <td><var>function, iterable</var><big>[</big><var>, initializer</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Apply <var>function</var> of two arguments cumulatively to the items of
  <var>iterable</var>, from left to right, so as to reduce the iterable to
  a single value.  For example, <code>reduce(lambda x, y: x+y, [1, 2,
  3, 4, 5])</code> calculates <code>((((1+2)+3)+4)+5)</code>.  The left argument,
  <var>x</var>, is the accumulated value and the right argument, <var>y</var>,
  is the update value from the <var>iterable</var>.  If the optional
  <var>initializer</var> is present, it is placed before the items of the
  iterable in the calculation, and serves as a default when the
  iterable is empty.  If <var>initializer</var> is not given and
  <var>iterable</var> contains only one item, the first item is returned.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-61' xml:id='l2h-61' class="function">reload</tt></b>(</nobr></td>
  <td><var>module</var>)</td></tr></table></dt>
<dd>
  Reload a previously imported <var>module</var>.  The
  argument must be a module object, so it must have been successfully
  imported before.  This is useful if you have edited the module
  source file using an external editor and want to try out the new
  version without leaving the Python interpreter.  The return value is
  the module object (the same as the <var>module</var> argument).

<p>
When <code>reload(module)</code> is executed:

<p>

<ul>
<li>Python modules' code is recompiled and the module-level code
    reexecuted, defining a new set of objects which are bound to names in
    the module's dictionary.  The <code>init</code> function of extension
    modules is not called a second time.

<p>
</li>
<li>As with all other objects in Python the old objects are only
    reclaimed after their reference counts drop to zero.

<p>
</li>
<li>The names in the module namespace are updated to point to
    any new or changed objects.

<p>
</li>
<li>Other references to the old objects (such as names external
    to the module) are not rebound to refer to the new objects and
    must be updated in each namespace where they occur if that is
    desired.

<p>
</li>
</ul>

<p>
There are a number of other caveats:

<p>
If a module is syntactically correct but its initialization fails,
  the first <tt class="keyword">import</tt> statement for it does not bind its name
  locally, but does store a (partially initialized) module object in
  <code>sys.modules</code>.  To reload the module you must first
  <tt class="keyword">import</tt> it again (this will bind the name to the partially
  initialized module object) before you can <tt class="function">reload()</tt> it.

<p>
When a module is reloaded, its dictionary (containing the module's
  global variables) is retained.  Redefinitions of names will override
  the old definitions, so this is generally not a problem.  If the new
  version of a module does not define a name that was defined by the
  old version, the old definition remains.  This feature can be used
  to the module's advantage if it maintains a global table or cache of
  objects -- with a <tt class="keyword">try</tt> statement it can test for the
  table's presence and skip its initialization if desired:

<p>
<div class="verbatim"><pre>
try:
    cache
except NameError:
    cache = {}
</pre></div>

<p>
It is legal though generally not very useful to reload built-in or
  dynamically loaded modules, except for <tt class="module"><a href="module-sys.html">sys</a></tt>,
  <tt class="module"><a href="module-main.html">__main__</a></tt> and <tt class="module"><a href="module-builtin.html">__builtin__</a></tt>.  In
  many cases, however, extension modules are not designed to be
  initialized more than once, and may fail in arbitrary ways when
  reloaded.

<p>
If a module imports objects from another module using <tt class="keyword">from</tt>
  ... <tt class="keyword">import</tt> ..., calling <tt class="function">reload()</tt> for
  the other module does not redefine the objects imported from it --
  one way around this is to re-execute the <tt class="keyword">from</tt> statement,
  another is to use <tt class="keyword">import</tt> and qualified names
  (<var>module</var>.<var>name</var>) instead.

<p>
If a module instantiates instances of a class, reloading the module
  that defines the class does not affect the method definitions of the
  instances -- they continue to use the old class definition.  The
  same is true for derived classes.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-62' xml:id='l2h-62' class="function">repr</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return a string containing a printable representation of an object.
  This is the same value yielded by conversions (reverse quotes).
  It is sometimes useful to be able to access this operation as an
  ordinary function.  For many types, this function makes an attempt
  to return a string that would yield an object with the same value
  when passed to <tt class="function">eval()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-63' xml:id='l2h-63' class="function">reversed</tt></b>(</nobr></td>
  <td><var>seq</var>)</td></tr></table></dt>
<dd>
  Return a reverse iterator.  <var>seq</var> must be an object which
  supports the sequence protocol (the __len__() method and the
  <tt class="method">__getitem__()</tt> method with integer arguments starting at
  <code>0</code>).
  
<span class="versionnote">New in version 2.4.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-64' xml:id='l2h-64' class="function">round</tt></b>(</nobr></td>
  <td><var>x</var><big>[</big><var>, n</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the floating point value <var>x</var> rounded to <var>n</var> digits
  after the decimal point.  If <var>n</var> is omitted, it defaults to zero.
  The result is a floating point number.  Values are rounded to the
  closest multiple of 10 to the power minus <var>n</var>; if two multiples
  are equally close, rounding is done away from 0 (so. for example,
  <code>round(0.5)</code> is <code>1.0</code> and <code>round(-0.5)</code> is <code>-1.0</code>).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-65' xml:id='l2h-65' class="function">set</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>iterable</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a set whose elements are taken from <var>iterable</var>.  The elements
  must be immutable.  To represent sets of sets, the inner sets should
  be <tt class="class">frozenset</tt> objects.  If <var>iterable</var> is not specified,
  returns a new empty set, <code>set([])</code>.
  
<span class="versionnote">New in version 2.4.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-66' xml:id='l2h-66' class="function">setattr</tt></b>(</nobr></td>
  <td><var>object, name, value</var>)</td></tr></table></dt>
<dd>
  This is the counterpart of <tt class="function">getattr()</tt>.  The arguments are an
  object, a string and an arbitrary value.  The string may name an
  existing attribute or a new attribute.  The function assigns the
  value to the attribute, provided the object allows it.  For example,
  <code>setattr(<var>x</var>, '<var>foobar</var>', 123)</code> is equivalent to
  <code><var>x</var>.<var>foobar</var> = 123</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-67' xml:id='l2h-67' class="function">slice</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>start,</var><big>]</big><var> stop</var><big>[</big><var>, step</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a slice object representing the set of indices specified by
  <code>range(<var>start</var>, <var>stop</var>, <var>step</var>)</code>.  The <var>start</var>
  and <var>step</var> arguments default to <code>None</code>.  Slice objects have
  read-only data attributes <tt class="member">start</tt>, <tt class="member">stop</tt> and
  <tt class="member">step</tt> which merely return the argument values (or their
  default).  They have no other explicit functionality; however they
  are used by Numerical Python<a id='l2h-86' xml:id='l2h-86'></a> and other third
  party extensions.  Slice objects are also generated when extended
  indexing syntax is used.  For example: "<tt class="samp">a[start:stop:step]</tt>" or
  "<tt class="samp">a[start:stop, i]</tt>".
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-68' xml:id='l2h-68' class="function">sorted</tt></b>(</nobr></td>
  <td><var>iterable</var><big>[</big><var>, cmp</var><big>[</big><var>,
                         key</var><big>[</big><var>, reverse</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a new sorted list from the items in <var>iterable</var>.

<p>
The optional arguments <var>cmp</var>, <var>key</var>, and <var>reverse</var> have
  the same meaning as those for the <tt class="method">list.sort()</tt> method
  (described in section&nbsp;<a href="typesseq-mutable.html#typesseq-mutable">3.6.4</a>).

<p>
<var>cmp</var> specifies a custom comparison function of two arguments
  (iterable elements) which should return a negative, zero or positive
  number depending on whether the first argument is considered smaller
  than, equal to, or larger than the second argument:
  "<tt class="samp"><var>cmp</var>=<tt class="keyword">lambda</tt> <var>x</var>,<var>y</var>:
  <tt class="function">cmp</tt>(x.lower(), y.lower())</tt>"
<p>
<var>key</var> specifies a function of one argument that is used to
     extract a comparison key from each list element:
     "<tt class="samp"><var>key</var>=<tt class="function">str.lower</tt></tt>"
<p>
<var>reverse</var> is a boolean value.  If set to <code>True</code>, then the
     list elements are sorted as if each comparison were reversed.

<p>
In general, the <var>key</var> and <var>reverse</var> conversion processes are
  much faster than specifying an equivalent <var>cmp</var> function.  This is
  because <var>cmp</var> is called multiple times for each list element while
  <var>key</var> and <var>reverse</var> touch each element only once.

<p>

<span class="versionnote">New in version 2.4.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-69' xml:id='l2h-69' class="function">staticmethod</tt></b>(</nobr></td>
  <td><var>function</var>)</td></tr></table></dt>
<dd>
  Return a static method for <var>function</var>.

<p>
A static method does not receive an implicit first argument.
  To declare a static method, use this idiom:

<p>
<div class="verbatim"><pre>
class C:
    @staticmethod
    def f(arg1, arg2, ...): ...
</pre></div>

<p>
The <code>@staticmethod</code> form is a function decorator - see the description
  of function definitions in chapter 7 of the
  <em class="citetitle"><a
 href="../ref/function.html"
 title="Python Reference Manual"
 >Python Reference Manual</a></em> for details.

<p>
It can be called either on the class (such as <code>C.f()</code>) or on an
  instance (such as <code>C().f()</code>).  The instance is ignored except
  for its class.

<p>
Static methods in Python are similar to those found in Java or C++.
  For a more advanced concept, see <tt class="function">classmethod()</tt> in this
  section.

<p>
For more information on static methods, consult the documentation on the
  standard type hierarchy in chapter 3 of the
  <em class="citetitle"><a
 href="../ref/types.html"
 title="Python Reference Manual"
 >Python Reference Manual</a></em> (at the bottom).
  
<span class="versionnote">New in version 2.2.</span>

<span class="versionnote">Changed in version 2.4:
Function decorator syntax added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-70' xml:id='l2h-70' class="function">str</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>object</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a string containing a nicely printable representation of an
  object.  For strings, this returns the string itself.  The
  difference with <code>repr(<var>object</var>)</code> is that
  <code>str(<var>object</var>)</code> does not always attempt to return a string
  that is acceptable to <tt class="function">eval()</tt>; its goal is to return a
  printable string.  If no argument is given, returns the empty
  string, <code>''</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-71' xml:id='l2h-71' class="function">sum</tt></b>(</nobr></td>
  <td><var>iterable</var><big>[</big><var>, start</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Sums <var>start</var> and the items of an <var>iterable</var> from left to
  right and returns the total.  <var>start</var> defaults to <code>0</code>.
  The <var>iterable</var>'s items are normally numbers, and are not allowed
  to be strings.  The fast, correct way to concatenate a sequence of
  strings is by calling <code>''.join(<var>sequence</var>)</code>.
  Note that <code>sum(range(<var>n</var>), <var>m</var>)</code> is equivalent to
  <code>reduce(operator.add, range(<var>n</var>), <var>m</var>)</code>
  
<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-72' xml:id='l2h-72' class="function">super</tt></b>(</nobr></td>
  <td><var>type</var><big>[</big><var>, object-or-type</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the superclass of <var>type</var>.  If the second argument is omitted
  the super object returned is unbound.  If the second argument is an
  object, <code>isinstance(<var>obj</var>, <var>type</var>)</code> must be true.  If
  the second argument is a type, <code>issubclass(<var>type2</var>,
  <var>type</var>)</code> must be true.
  <tt class="function">super()</tt> only works for new-style classes.

<p>
A typical use for calling a cooperative superclass method is:
<div class="verbatim"><pre>
class C(B):
    def meth(self, arg):
        super(C, self).meth(arg)
</pre></div>

<p>
Note that <tt class="function">super</tt> is implemented as part of the binding process for
  explicit dotted attribute lookups such as
  "<tt class="samp">super(C, self).__getitem__(name)</tt>".  Accordingly, <tt class="function">super</tt> is
  undefined for implicit lookups using statements or operators such as
  "<tt class="samp">super(C, self)[name]</tt>".

<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-73' xml:id='l2h-73' class="function">tuple</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>iterable</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a tuple whose items are the same and in the same order as
  <var>iterable</var>'s items.  <var>iterable</var> may be a sequence, a
  container that supports iteration, or an iterator object.
  If <var>iterable</var> is already a tuple, it
  is returned unchanged.  For instance, <code>tuple('abc')</code> returns
  <code>('a', 'b', 'c')</code> and <code>tuple([1, 2, 3])</code> returns
  <code>(1, 2, 3)</code>.  If no argument is given, returns a new empty
  tuple, <code>()</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-74' xml:id='l2h-74' class="function">type</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return the type of an <var>object</var>.  The return value is a
  type<a id='l2h-75' xml:id='l2h-75'></a> object.  The <tt class="function">isinstance()</tt> built-in
  function is recommended for testing the type of an object.

<p>
With three arguments, <tt class="function">type</tt> functions as a constructor
  as detailed below.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-76' xml:id='l2h-76' class="function">type</tt></b>(</nobr></td>
  <td><var>name, bases, dict</var>)</td></tr></table></dt>
<dd>
  Return a new type object.  This is essentially a dynamic form of the
  <tt class="keyword">class</tt> statement. The <var>name</var> string is the class name
  and becomes the <tt class="member">__name__</tt> attribute; the <var>bases</var> tuple
  itemizes the base classes and becomes the <tt class="member">__bases__</tt>
  attribute; and the <var>dict</var> dictionary is the namespace containing
  definitions for class body and becomes the <tt class="member">__dict__</tt>
  attribute.  For example, the following two statements create
  identical <tt class="class">type</tt> objects:

<p>
<div class="verbatim"><pre>
  &gt;&gt;&gt; class X(object):
  ...     a = 1
  ...     
  &gt;&gt;&gt; X = type('X', (object,), dict(a=1))
</pre></div>

<span class="versionnote">New in version 2.2.</span>
          
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-77' xml:id='l2h-77' class="function">unichr</tt></b>(</nobr></td>
  <td><var>i</var>)</td></tr></table></dt>
<dd>
  Return the Unicode string of one character whose Unicode code is the
  integer <var>i</var>.  For example, <code>unichr(97)</code> returns the string
  <code>u'a'</code>.  This is the inverse of <tt class="function">ord()</tt> for Unicode
  strings.  The valid range for the argument depends how Python was
  configured - it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF].
  <tt class="exception">ValueError</tt> is raised otherwise.
  
<span class="versionnote">New in version 2.0.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-78' xml:id='l2h-78' class="function">unicode</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>object</var><big>[</big><var>, encoding
				    </var><big>[</big><var>, errors</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the Unicode string version of <var>object</var> using one of the
  following modes:

<p>
If <var>encoding</var> and/or <var>errors</var> are given, <code>unicode()</code>
  will decode the object which can either be an 8-bit string or a
  character buffer using the codec for <var>encoding</var>. The
  <var>encoding</var> parameter is a string giving the name of an encoding;
  if the encoding is not known, <tt class="exception">LookupError</tt> is raised.
  Error handling is done according to <var>errors</var>; this specifies the
  treatment of characters which are invalid in the input encoding.  If
  <var>errors</var> is <code>'strict'</code> (the default), a
  <tt class="exception">ValueError</tt> is raised on errors, while a value of
  <code>'ignore'</code> causes errors to be silently ignored, and a value of
  <code>'replace'</code> causes the official Unicode replacement character,
  <code>U+FFFD</code>, to be used to replace input characters which cannot
  be decoded.  See also the <tt class="module"><a href="module-codecs.html">codecs</a></tt> module.

<p>
If no optional parameters are given, <code>unicode()</code> will mimic the
  behaviour of <code>str()</code> except that it returns Unicode strings
  instead of 8-bit strings. More precisely, if <var>object</var> is a
  Unicode string or subclass it will return that Unicode string without
  any additional decoding applied.

<p>
For objects which provide a <tt class="method">__unicode__()</tt> method, it will
  call this method without arguments to create a Unicode string. For
  all other objects, the 8-bit string version or representation is
  requested and then converted to a Unicode string using the codec for
  the default encoding in <code>'strict'</code> mode.

<p>

<span class="versionnote">New in version 2.0.</span>

<span class="versionnote">Changed in version 2.2:
Support for <tt class="method">__unicode__()</tt> added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-79' xml:id='l2h-79' class="function">vars</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>object</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Without arguments, return a dictionary corresponding to the current
  local symbol table.  With a module, class or class instance object
  as argument (or anything else that has a <tt class="member">__dict__</tt>
  attribute), returns a dictionary corresponding to the object's
  symbol table.  The returned dictionary should not be modified: the
  effects on the corresponding symbol table are undefined.<a name="tex2html4"
  href="#foot1083"><sup>2.4</sup></a></dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-80' xml:id='l2h-80' class="function">xrange</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>start,</var><big>]</big><var> stop</var><big>[</big><var>, step</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  This function is very similar to <tt class="function">range()</tt>, but returns an
  ``xrange object'' instead of a list.  This is an opaque sequence
  type which yields the same values as the corresponding list, without
  actually storing them all simultaneously.  The advantage of
  <tt class="function">xrange()</tt> over <tt class="function">range()</tt> is minimal (since
  <tt class="function">xrange()</tt> still has to create the values when asked for
  them) except when a very large range is used on a memory-starved
  machine or when all of the range's elements are never used (such as
  when the loop is usually terminated with <tt class="keyword">break</tt>).

<p>
<span class="note"><b class="label">Note:</b>
<tt class="function">xrange()</tt> is intended to be simple and fast.
        Implementations may impose restrictions to achieve this.
        The C implementation of Python restricts all arguments to
        native C longs ("short" Python integers), and also requires
        that the number of elements fit in a native C long.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-81' xml:id='l2h-81' class="function">zip</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>iterable, ...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  This function returns a list of tuples, where the <var>i</var>-th tuple contains
  the <var>i</var>-th element from each of the argument sequences or iterables.
  The returned list is truncated in length to the length of
  the shortest argument sequence.  When there are multiple arguments
  which are all of the same length, <tt class="function">zip()</tt> is
  similar to <tt class="function">map()</tt> with an initial argument of <code>None</code>.
  With a single sequence argument, it returns a list of 1-tuples.
  With no arguments, it returns an empty list.
  
<span class="versionnote">New in version 2.0.</span>

<p>

<span class="versionnote">Changed in version 2.4:
Formerly, <tt class="function">zip()</tt> required at least one argument
  and <code>zip()</code> raised a <tt class="exception">TypeError</tt> instead of returning
  an empty list.</span>

</dl>

<p>
<br><hr><h4>Footnotes</h4>
<dl>
<dt><a name="foot419">... module.</a><A
 href="built-in-funcs.html#tex2html2"><sup>2.2</sup></a></dt>
<dd>It is used relatively
  rarely so does not warrant being made into a statement.

</dd>
<dt><a name="foot1197">... used.</a><A
 href="built-in-funcs.html#tex2html3"><sup>2.3</sup></a></dt>
<dd>
    Specifying a buffer size currently has no effect on systems that
    don't have <tt class="cfunction">setvbuf()</tt>.  The interface to specify the
    buffer size is not done using a method that calls
    <tt class="cfunction">setvbuf()</tt>, because that may dump core when called
    after any I/O has been performed, and there's no reliable way to
    determine whether this is the case.

</dd>
<dt><a name="foot1083">... undefined.</a><A
 href="built-in-funcs.html#tex2html4"><sup>2.4</sup></a></dt>
<dd>
    In the current implementation, local variable bindings cannot
    normally be affected this way, but variables retrieved from
    other scopes (such as modules) can be.  This may change.

</dd>
</dl>
<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="2. built-in Objects"
  href="builtin.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="2. built-in Objects"
  href="builtin.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="2.2 non-essential Built-in Functions"
  href="non-essential-built-in-funcs.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python库参考</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'><b class="navlabel">前一节:</b> <a class="sectref" rel="prev" href="builtin.html">2. 内置对象</a> <b class="navlabel">上一级:</b> <a class="sectref" rel="parent" href="builtin.html">2. 内置对象</a> <b class="navlabel">下一节:</b> <a class="sectref" rel="next" href="non-essential-built-in-funcs.html">2.2 次要的内置函数</a></div>
</div>
<hr />
<span class="release-info">2.5.1 版， 文档更新在 2007，4，18。翻译：<a href="http://www.zkfarmer.org">zkfarmer</a>。</span></div>
<!--End of Navigation Panel-->
<address>
关于建议修改的信息查阅 <i><a href="about.html">关于这个文档...</a></i> 。
</address>
</body>
</html>
